#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2020/3/7  15:11
# @Author: 余浪人
# @email: yulangren520@gmail.com
from apps.control import sys_bp
from flask import request, render_template, jsonify
from flask_login import login_required
from apps.lib.public import edit_data
from apps.forms.separatePage_form import TL_SeparatePage_Form
from apps.models.separate_model import TL_Separate_Model, db


@sys_bp.route('/separate_page', endpoint='separate_page', methods=['GET', 'POST'])
@login_required
def separate_page():
    try:
        raw = TL_Separate_Model.query.filter_by().first()
    except:
        raw = {}
    if request.method == 'POST':
        try:
            return edit_data(TL_SeparatePage_Form, TL_Separate_Model, db, raw.id)
        except:
            return jsonify({'status': 4, 'msg': '写入致命错误'})
    form = TL_SeparatePage_Form(data=dict(raw))
    return render_template('system_template/separate_page.html', form=form)
